#include <iostream>
#include <cstring>
#include "shell.h"
#include "tool.h"
#include "string.h"
using namespace std;

/*
 * @E=1@T=2@W=2@M=1@d=4@D=4@B=4800@C=9600@L=1,8@V=1@W=2@d=4@Q=1
 * @Y=222222@E=1@T=2@A=1@P=?@W=2@d=4@D=4S@F=1@B=4800@C=9600@V=1@W=2@d=4@S=1
 *
 * */

int send(uint8_t* data,int len){
    printf(">>>>>>\n");
    for(int i=0;i<len;i++){
        printf("%x ",data[i]);
    }
    printf("\n<<<<<<\n");
    return len;
}
void hello(char* data,int len){
    //TODO
    printf("hello world\n");
}
void hi(char* data,int len){
    //TODO
    printf("hi world\n");
}
execute_handle execute_group[]={
        {"hello" ,&hello},
        {"hi" ,&hi},
};


int main(){


    int recv_len=0;
    shell_init();
    register_inform(send);
    register_execute(execute_group,sizeof(execute_group)/sizeof(execute_handle));
    for(;;) {
        cin >> shell_var.shell_buf;       //接收串口数据
        if(!strncmp("break",shell_var.shell_buf,strlen("break")))
            break;
        recv_len=strlen(shell_var.shell_buf);   //TODO  缓存数据的长度获取

        unpack(shell_var.shell_buf, recv_len);
        execute(shell_var.node_group,get_node_num());
        recycle();


    }
    return 0;
}